import { createAxios } from '@/utils/http/axios';

enum Api {
  pageGetAll = '/virtual/virtualDevice/pageGetAll',
  updateDeviceStatus = '/virtual/virtualDevice/updateDeviceStatus',
  saveUpdateDeviceParam = '/virtual/virtualDevice/saveUpdateDeviceParam',
  listDeviceParam = '/virtual/virtualDevice/listDeviceParam',
  sendDpParam = '/virtual/virtualDevice/sendParam',
  sendNtp = '/virtual/virtualDevice/sendNtp',
  uploadTopology = '/virtual/virtualDevice/uploadTopology',
  sendWarn = '/virtual/virtualDevice/sendWarn',
  sendEvent = '/virtual/virtualDevice/sendEvent',
  setDeviceLatLng = '/virtual/virtualDevice/setDeviceLatLng',
  addVirtualDevice = '/virtual/virtualDevice/addVirtualDevice',
  getVirtualDevice = '/virtual/virtualDevice/getVirtualDevice',
  startSendParamTask = '/virtual/virtualDevice/startSendParamTask',
  randomAddVirtualDevice = '/virtual/virtualDevice/randomAddVirtualDevice',
  disconnectNotKeepOnline = '/virtual/virtualDevice/disconnectNotKeepOnline',
  updateRandomOnlineNum = '/virtual/virtualDevice/randomOnline',
}

export function getVirtualDeviceApi(data: { sn: string }) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.getVirtualDevice,
    data: data,
  });
}

export function addVirtualDeviceApi(data: any) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.addVirtualDevice,
    data: data,
  });
}

export function pageGetAllApi(data: {
  pageNum: number;
  pageSize: number;
  snStr: string;
  pnStr: string;
  productId: number;
  deviceStatus: DeviceStatusEnum;
}) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.pageGetAll,
    data: data,
  });
}

export enum DeviceStatusEnum {
  // ONLINE=在线，OFFLINE=离线
  ONLINE = 'ONLINE',
  OFFLINE = 'OFFLINE',
}

export function updateDeviceStatusApi(data: { snList: string[]; deviceStatus: DeviceStatusEnum }) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.updateDeviceStatus,
    data: data,
  });
}

export function saveUpdateDeviceParamApi(data: { sn: string; paramMap: any }) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.saveUpdateDeviceParam,
    data,
  });
}

export function startSendParamTaskApi(data: { sn: string; cron: string; func: string }) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.startSendParamTask,
    data,
  });
}

export function sendNtpApi(data: { sn: string }): Promise<number> {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.sendNtp,
    data,
  });
}

export function sendWarnApi(data: { sn: string; warnBitList: [] }): Promise<number> {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.sendWarn,
    data,
  });
}

export function sendEventApi(data: { sn: string; event: number }): Promise<number> {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.sendEvent,
    data,
  });
}

export function listDeviceParamApi(data: { sn: string }) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.listDeviceParam,
    data,
  });
}

export function sendParamApi(data: { sn: string; func: number }) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.sendDpParam,
    data,
  });
}

export function uploadTopologyApi(data: { sn: string }) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.uploadTopology,
    data,
  });
}

export function setDeviceLatLngApi(data: { sn: string; lat: string; lng: string }) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.setDeviceLatLng,
    data,
  });
}

export function randomAddVirtualDeviceApi(data: {
  productId: string;
  addDevicesSum: number;
}): Promise<number> {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.randomAddVirtualDevice,
    data,
  });
}

export function disconnectNotKeepOnlineApi(data: { num: number }): Promise<number> {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.disconnectNotKeepOnline,
    data: data,
  });
}

export function updateRandomOnlineNumApi(data: { num: number }) {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.updateRandomOnlineNum,
    data: data,
  });
}
